package com.qianying.controller.admin;

import com.qianying.comment.CommonResult;
import com.qianying.entity.CustomBrand;
import com.qianying.service.CustomBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 品牌管理控制器
 * @author check
 * @date 2023-10-20
 */
@RestController
@RequestMapping("/admin/brand")
@Tag(name = "客户：品牌管理(自有品牌和供应商)", description = "品牌信息管理接口")
@CrossOrigin
public class CustomBrandController {

    @Autowired
    private CustomBrandService brandService;

    @PostMapping
    @Operation(summary = "添加品牌", description = "创建新品牌信息")
    public CommonResult<?> save(@RequestBody CustomBrand customBrand) {
        return brandService.save(customBrand);
    }

    @PutMapping
    @Operation(summary = "更新品牌", description = "根据ID更新品牌信息")
    public CommonResult<?> update(@RequestBody CustomBrand customBrand) {
        return brandService.update(customBrand);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除品牌", description = "根据ID删除品牌信息")
    public CommonResult<?> delete(@PathVariable @Parameter(description = "品牌ID") Long id) {
        return brandService.delete(id);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取单个品牌", description = "根据ID查询品牌详情")
    public CommonResult<CustomBrand> getById(@PathVariable @Parameter(description = "品牌ID") Long id) {
        return brandService.getById(id);
    }

    @GetMapping("/list")
    @Operation(summary = "获取所有品牌", description = "查询所有品牌列表")
    public CommonResult<List<CustomBrand>> list() {
        return brandService.listAll();
    }

    @GetMapping("/listByCustomId")
    @Operation(summary = "按客户ID查询品牌", description = "查询指定客户关联的所有品牌")
    public CommonResult<List<CustomBrand>> listByCustomId(@RequestParam @Parameter(description = "客户ID") Long customId) {
        return brandService.listByCustomId(customId);
    }

    @GetMapping("/listByStatus")
    @Operation(summary = "按状态查询品牌", description = "查询指定状态的所有品牌")
    public CommonResult<List<CustomBrand>> listByStatus(@RequestParam @Parameter(description = "状态(1:正常,0:禁用)") Integer status) {
        return brandService.listByStatus(status);
    }
}